<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- ===== 引入谷歌字体 ===== -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap">

    <title>编辑分类</title>
    <style>
        /*===== CSS变量 =====*/
        :root{
            --first-color: #0C5DF4;
            --bg-color: #F5F5F5;
            --sub-color: #B6CEFC;
            --white-color: #FFF;

            /*===== 规定字体  =====*/
            --body-font: 'Poppins', sans-serif;
            --normal-font-size: 1rem;
            --small-font-size: .875rem;
        }

        /*===== 基础规定 =====*/
        *,::before,::after{
            box-sizing: border-box;
        }
        body{
            margin: 0;
            padding: 2rem;
            font-family: var(--body-font);
            font-size: var(--normal-font-size);
            background-color: var(--bg-color);
            color: var(--first-color);
        }
        h2{
            color: var(--first-color);
        }
        form {
            background-color: var(--white-color);
            padding: 2rem;
            border-radius: .5rem;
            max-width: 400px;
            margin: 0 auto;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        label {
            display: block;
            margin-bottom: .5rem;
            color: var(--first-color);
        }
        input[type="text"], button {
            width: 100%;
            padding: 1rem;
            margin-bottom: 1rem;
            border-radius: .5rem;
            border: 1px solid var(--first-color);
        }
        button {
            background-color: var(--first-color);
            color: var(--white-color);
            border: none;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        button:hover {
            background-color: #0a49c2;
        }
        /* 返回链接样式 */
        .back-link {
            display: block;
            margin-top: 2rem;
            text-align: center;
            color: var(--first-color);
            text-decoration: underline;
            cursor: pointer;
        }
    </style>
</head>

<body>
<% if (request.getAttribute("categoryError") != null) { %>
<div id="error-message"><%= request.getAttribute("categoryError") %></div>
<% } %>
<h2>编辑分类</h2>
<!-- 表单用于编辑分类 -->
<form action="${pageContext.request.contextPath}/user/doEditCategory" method="post" onsubmit="return confirmEditCategory()">
    <input type="hidden" name="categoryId" value="${sessionScope.category.categoryId}" />
    <label for="categoryName">分类名称:</label>
    <input type="text" id="categoryName" name="categoryName" value="${sessionScope.category.categoryName}" required />
    <button type="submit" class="edit-button">提交</button>
</form>
<div class="back-link" onclick="goBack()">返回上一层</div>
<script>
    function confirmEditCategory() {
        if (!confirm('您确定要提交更改吗？')) {
            return false; // 取消提交
        }
        window.location.href = 'javascript:history.back()';
    }
    function goBack() {
        window.history.back();
    }
    window.onload = function () {
        var errorMessage = document.getElementById('error-message');
        if (errorMessage) {
            alert(errorMessage.textContent);
        }
    };

</script>
</body>
</html>